<?php
class Validator {
	
	/**
	 * Not valid field response
	 *
	 */
	const NOTVALID_EMTY_FIELD = 0;
	
	/**
	 * Not valid email response
	 *
	 */
	const NOTVALID_EMAIL = 1;
	
	/**
	 * Ok response
	 *
	 */
	const OK = 2;
	
	/**
	 * Password missmatch response
	 *
	 */
	const PASSWORD_MISSMATCH = 3;
	
	/**
	 * Validate text field
	 *
	 * @param string $fieldName
	 * @return Validator response
	 */
	public static function validateField ($fieldName) {
		if(!empty($fieldName)) {
			$fieldName = htmlspecialchars($fieldName);
			return $fieldName;
		}
		else {
			return self::NOTVALID_EMTY_FIELD;
		}
	}
	
	/**
	 * Validate email field
	 *
	 * @param string $email
	 * @return Validator response
	 */
	public static function validateEmail($email) {
		if(preg_match('|([a-z0-9_\.\-]{1,20})@([a-z0-9\.\-]{1,20})\.([a-z]{2,4})|is', $email)) {
			return $email;
		}
		else {
			return self::NOTVALID_EMAIL;
		}
		
	}
	
	/**
	 * Compare passwords
	 *
	 * @param string $password
	 * @param string $rePassword
	 * @return Validator response
	 */
	public static function matchPasswords($password, $rePassword) {
		if($password != $rePassword) {
			return self::PASSWORD_MISSMATCH;
		}
		return self::OK;
	}

}